<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\mill\model;

use think\Model;
use app\user\model\Role as RoleModel;
use util\Tree;
use think\helper\Hash;
use think\Db;

/**
 * 统计模型
 */
class Stat extends Model
{

    /**
     * 获取侧栏节点
     * @param string $module 模块名
     * @param int $menu_id 菜单ID
     * @author 蔡伟明 <314013107@qq.com>
     * @return array|mixed
     */
    public static function getMenu($module = 'mill',$menu_id = 0,$field = 'id')
    {
        $menus = '';

        if (!$menus) {
            // 当前顶级节点id

            // 获取当前模块下的所有节点
            $map = [
                'module' => $module,
                'status' => 1,
            ];
            if(!empty($menu_id))$map[$field] = $menu_id;
            // 非开发模式，只显示可以显示的菜单
            if (config('develop_mode') == 0) {
                //$map['online_hide'] = 0;
            }
            $menus = Db::name('admin_menu')->field('id,pid,module,title,url_value,url_type,url_target,icon,params,online_hide')->where($map)->order('sort,id')->select();

            // 解析模块链接
            foreach ($menus as $key => &$menu) {

                // 没有访问权限的节点不显示
                if (!RoleModel::checkAuth($menu['id'])) {
                    unset($menus[$key]);
                    continue;
                }
                if ($menu['url_value'] != '' && ($menu['url_type'] == 'module_admin' || $menu['url_type'] == 'module_home')) {
                    $menu['url_value'] = $menu['url_type'] == 'module_admin' ? admin_url($menu['url_value'], $menu['params']) : home_url($menu['url_value'], $menu['params']);
                }
                if($field == 'id')$menu['child'] = self::getMenu($module,$menu['id'],'pid');
            }

        }
        return $menus;
    }

    //小程序首页统计同比计算
    public static function doSame($num = 0,$upmum = 0){

        $re = empty($num)?-100:round(($num-$upmum)*100/$num,2);
        if(empty($num) && empty($upmum))$re = 0;
        return $re;

    }

    //用户头部
    public static function userHtml(){

        $html = '<div class="banner"><img style="width: 1980px;height: 150px;" src="'.config('template.tpl_replace_string')['__HOME_IMG__'].'/usertop.png"></div>';

        return $html;
    }

    //审核头部
    public static function enableHtml(){

        $html = '<div class="banner"><img style="width: 1980px;height: 150px;" src="'.config('template.tpl_replace_string')['__HOME_IMG__'].'/designBanner.png"></div>';

        return $html;
    }

    //排名统计
    public static function rankHtmlModel(){

        $html = '<div class="month">
            <div class="title">排名</div>
            <div class="box" id="rank">
                <div class="item s_center">
                    <span>1</span>
                    <h5>—</h5>
                    <font>—</font>
                </div>
                <div class="item s_center">
                    <span>2</span>
                    <h5>—</h5>
                    <font>—</font>
                </div>
                <div class="item s_center">
                    <span>3</span>
                    <h5>—</h5>
                    <font>—</font>
                </div>
            </div>
        </div>';

        $js = '<script type="text/javascript">
                    //初始化最高排名
                    function statInit (id,data) {
                        var rank = data.rank;
                        var html = "";
                        var i = 1;
                        $.each(rank,function(title,value){
                            if(i>3)return false;
                            value = ""+value;
                            var arr = value.split("___");
                            var font  = "";
                            $.each(arr,function(ai,ak) {
                                font += "<font>"+ak+"</font>";
                            });
                            html += "<div class=\\"item s_center\\">"
                                        +"<span>"+i+"</span>"
                                        +"<h5>"+title+"</h5>"
                                        +font
                                    +"</div>";
                            i++;
                        });
                        $("#"+id).html(html);
                    }
                </script>';

        return $html.$js;

    }

    //图形统计
    public static function chartsHtmlModel($option = '',$i = 3){

        $width = '100%';

        if($i == 2)$width = 'calc(100% - 320px)';
        elseif ($i == 3)$width = 'calc(100% - 519px)';

        $html = '<div class="charts" id="echarts" style="width:'.$width.'"></div>';

        $js = '<script type="text/javascript">
                
                //初始化echarts
                function echartsInit (id,data) {
        
                    var chartDom = document.getElementById(id);
                    var myChart = echarts.init(chartDom);
                    
                    var option = '.$option.';
        
                    option && myChart.setOption(option);
                }
                
                
            </script>';

        return $html.$js;

    }

    //年份表格统计
    public static function yearTableHtmlModel($url = ''){

        $html = '<div class="changeYear">
            <div id="year-panel" class="s_center year-panel">
                <div class="left">
                    <span id="prev-decade"></span>至<span id="next-decade"></span>
                </div>
                <div class="right flex flex-center">
                    <i class="layui-icon layui-icon-left prev-decade"></i>
                    <span></span>
                    <i class="layui-icon layui-icon-right next-decade"></i>
                </div>
            </div>
            <div id="year-list" class="s_center wrap year-list"></div>
        </div>';

        $js = '<script type="text/javascript">
                // 统计数据渲染
                $(function(){
                    var currentYear = new Date().getFullYear();// 获取当前年份
                    var currentDecade = Number((""+currentYear).slice(0, -1)+"0"); // 初始十年起始年份
                    
                    // 创建年份表格
                    function showDecade() {
                        
                        $("#prev-decade").text(currentDecade);
                        $("#next-decade").text(currentDecade+9);
                        $("#current-decade").text(currentDecade + " - " + (currentDecade + 9));
                        
                        // 创建十个年份按钮
                        var yearListHtml = "";
                        for (var i = 0; i < 10; i++) {
                            var year = (currentDecade + i);
                            var selected =  "";
                            if(year == currentYear)selected = "on";
                            yearListHtml += "<a class=\\"year "+selected+"\\" data-year="+year+">"+year+"</a>";
                        }
                        $("#year-list").html(yearListHtml);
                    }
                    // 创建年份表格
                    if(!$("#year-list").html())showDecade();
        
                    // 上一十年按钮点击事件
                    $(".prev-decade").click(function() {
                        currentDecade -= 10;
                        showDecade();
                    });
        
                    // 下一十年按钮点击事件
                    $(".next-decade").click(function() {
                        currentDecade += 10;
                        showDecade();
                    });
                    
                    // 年份按钮点击事件
                    $("#year-list").on("click","a",function () {
                        $(this).addClass("on").siblings().removeClass("on");
                        // 在这里可以进行年份按钮点击后的其他逻辑操作
                        //获取统计
                        currentYear = $(this).attr("data-year");
                        
                        stat_echarts(currentYear);
                    });
                    
                });
                
                //更新统计数据
                function stat_echarts (year){
                    var url = "'.$url.'";
                    var param = {year:year};
                    $.get(url,param, function(data){
                        data = $.parseJSON(data);
                        //初始化最高排行
                        if (typeof statInit === "function")statInit("rank",data);
                        //初始化echarts
                        if (typeof echartsInit === "function")echartsInit("echarts",data);
                        
                    });
                }
                
                // 统计数据渲染
                stat_init_func["year_list"] = function() 
                {
                    $("#year-list").find("a.on").click();
                };
                
                
            </script>';

        return $html.$js;

    }

    //头部统计
    public static function topStatHtml($url = '',$option = '',$model = ['rank','charts','year']){

        $html = '';

        $model_html = [
            'rank'  =>  self::rankHtmlModel(),//排名统计
            'year'  =>  self::yearTableHtmlModel($url),//年份表格统计
            'charts'  =>  self::chartsHtmlModel($option,count($model)),//图形统计
        ];
        foreach ($model as $v){
            if(isset($model_html[$v]))$html .= $model_html[$v];
        }

        return $html;
    }

    //底部弹出显示详细信息
    public static function fixedHtml($menu = []){

        if(empty($menu))return '';

        $menu_html = '';
        foreach ($menu as $m){
            $menu_html .= '<div class="title fixed_lift_title" data-url="'.$m['url_value'].'" data-param="" data-json="">'.$m['title'].'</div>';
            if(!empty($m['child'])){
                $menu_html .= '<div class="list">';
                foreach ($m['child'] as $mk=>$mm){
                    $on = 'on';
                    if($mk > 0)$on = '';

                    $extra_class = isset($mm['extra_class'])?$mm['extra_class']:'';
                    $extra_attr = isset($mm['extra_attr'])?$mm['extra_attr']:'';

                    $menu_html .= '<div class="item h_center '.$extra_class.' '.$on.'" data-url="'.$mm['url_value'].'" '.$extra_attr.'>'.$mm['title'].'</div>';
                }
                $menu_html .= '</div>';
            }
        }

        $html = '
        <div class="fixed">
        <div class="close h_center"><img class="close-img" src="'.config('template.tpl_replace_string')['__HOME_IMG__'].'/downIcon.png" /></div>
        <div class="box s_center">
            <div class="left">'.$menu_html.'</div>
            <div class="right">
                <div class="title fixed_title"></div>
                <div class="infos s_center fixed_content"></div>
                <table id="fixed_table" lay-filter="fixed_table"></table>

            </div>
        </div>
    </div>
            <script type="text/javascript">
                $(function(){
                
                    var _fixed_item_height = $(".fixed .list .item").height();//左侧列表的高度
                    var _fixed_item_margin = ($(".fixed .list .item").outerHeight(true)-_fixed_item_height)/2;//左侧列表的位移
                    
                                
                    $("body").click(function(e) {
                        var obj = $(e.target);
                        
                        //打开弹出框
                        var obj_parent = obj.parents(".fixedName");
                        if(obj.is(".fixedName") || obj_parent.is(".fixedName")) {
                            obj = obj.is(".fixedName")?obj:obj_parent;
                            $(".fixed").addClass("on");
                            
                            //var json = obj.attr("data-json");
                            //$(".fixed_lift_title").attr("data-json",json);
                            //var data = $.parseJSON(json);
                            $(".fixed_lift_title").attr("data-param",obj.attr("data-param"));
                            //AJAX 加载数据
                            ajaxShow();
                            
                            var fixed_height = 382;//弹出框的总高度
                            var list_top = $(".fixed .list").position().top;//左侧列表到弹出框的距离
                            var list_height = $(".fixed .list").height();//左侧列表目前的高度
                            var list_height2 = fixed_height-list_top;//左侧列表到底部的高度
                            var list_count = $(".fixed .list .item").length;
                            //根据左侧列表的总高度 > 到底部的高度 , 则重新分配列表高度
                            //if(list_height > list_height2){
                            if(list_count > 4){
                            
                                var _list_height = ((list_height-list_height2)/list_count)/2;
                                
                                var item_height = $(".fixed .list .item").height();
                                var item_margin = ($(".fixed .list .item").outerHeight(true)-item_height);
                                
                            //console.log(item_height);
                            //console.log(_list_height);
                                item_height = item_height-_list_height;
                                item_margin = (item_margin-_list_height)/4.5;
                                
                                $(".fixed .list .item").css("height",item_height+"px");
                                $(".fixed .list .item").css("margin",item_margin+"px 0");
                            //console.log(item_height);
                            }
                            else{
                            
                                $(".fixed .list .item").css("height",_fixed_item_height+"px");
                                $(".fixed .list .item").css("margin",_fixed_item_margin+"px 0");
                            }
                            
                        }
                        //关闭弹出框
                        else if(obj.is(".close") || obj.is(".close-img") || ($(obj).closest(".fixed").length == 0 && !obj.is(".fixed-page") && !obj.is(".layui-icon-close"))){
                            $(".fixed").removeClass("on");
                        }
                        //左侧列表点击事件
                        else if(obj.is(".fixed .box .left .list .item")){
                            $(obj).addClass("on").siblings().removeClass("on");
                            $(".section").removeClass("on");
                            
                            var url = $(obj).attr("data-url");
                            var param = $(".fixed_lift_title").attr("data-param");
                            if(param)param = (url.indexOf("?") < 0 ? "?" : "&")+param;
                            
                            //AJAX 加载数据
                            ajaxList(url+param);
                            
                        }
                    });

                });
                
                //AJAX 获取详情信息
                function ajaxShow(){
                    
                    var url = $(".fixed_lift_title").attr("data-url");
                    var param = $(".fixed_lift_title").attr("data-param");
                    if(param)param = (url.indexOf("?") < 0 ? "?" : "&")+param;
                    
                    url = url+param;
                    $.get(url,{}, function(data){
                        data = $.parseJSON(data);
                        var title = data.title;
                        var columns = data.columns;
                        var row_list = data.row_list;
                        
                        var html = "";
                        
                        $.each(columns,function(i,v){
                            var val = row_list[v.field]?row_list[v.field]:"";
                            if(v.title)v.title += "：";
                            html += "<div class=\\"item\\">"+v.title+val+"</div>";
                        });
                        
                        $(".fixed_title").html(title);
                        $(".fixed_content").html(html);
                        
                        //加载列表信息
                        $(".fixed .box .left .list .on").click();
                    });
                }
                
                //AJAX 获取列表信息
                function ajaxList(url){
                    
                    $.get(url,{}, function(data){
                        data = $.parseJSON(data);
                        //渲染表格
                        fixedTable(data);
                        
                    });
                    
                }
                function fixedTable(data){
                
                    //表头
                    var columns = [];
                    //数据
                    var row_list = data.row_list;
                    
                    $.each(data.columns,function(i,v){
                        //居中
                        v.align = "center";
                        //列表内容
                        v.templet = function(d){
                            return d[v.field] != null?d[v.field]:"";
                        };
                        columns[i] = v;
                    });
                    columns = [columns];
                    
                    //设置css样式
                    var css = ".layui-table-header {background-color: #1a2c3d;}"+
                    "tr{background-color: #1a2c3d;}"+
                    ".layui-table thead tr {background-color: #1a2c3d;}"+
                    ".layui-table tbody tr:hover{background-color: #1a2c3dbd;}"+
                    ".layui-table-cell {color: #fff;}"+
                    ".layui-table-page .layui-laypage a {color: aliceblue;}"+
                    ".layui-table-page {text-align: right;}";
                    //设置分页样式
                    var page = {
                        theme: "#1E9FFF",
                        prev: "上一页",
                        next: "下一页",
                        layout:["prev", "page", "next"]
                    };
                    
                    layui.use(["table"], function(){
                        var table = layui.table;
        
                        var table_options = {
                            elem: "#fixed_table",
                            cols: columns,
                            data: row_list,
                            page: page,
                            limit: 6, // 数据表格默认全部显示
                            skin: "line",
                            css: css,
                            height: "245",
                            done: function(res, curr, count) {
                                
                                // 设置css样式
                                $(".fixed").find(".layui-table-view").css("border","none");
                                $(".fixed").find(".layui-table-view .layui-table[lay-skin=line]").css("border-width","0");
                                $(".fixed").find(".layui-table-view .layui-table[lay-skin=line]").css("width","100%");
                                $(".fixed").find(".layui-laypage a").addClass("fixed-page");
                                // 监听单元格点击事件
    
                            }
                        };
                        // 渲染表格
                        table.render(table_options);
        
                    });
                
                }
                
            </script>
        ';

        return $html;
    }

    //批次统计
    public static function orderToSpeedHtml($url = ''){

        $html = '
            <div class="topInfo s_center top_fixed_lift_title" data-url="'.$url.'"></div>
            <script type="text/javascript">
                $(function(){
                    
                    $("body").click(function(e) {
                        var obj = $(e.target);
                        
                        //打开弹出框
                        if(obj.is(".top_fixedName")) {
                            //AJAX获取数据
                            $(".top_fixed_lift_title").attr("data-param",obj.attr("data-param"));
                            //AJAX 加载数据
                            ajaxShowTop();
                            
                            $(".topInfo").nextAll().hide();
                            $(".topInfo").prevAll().hide();
                            $(".topInfo").show();
                        }
                        else{
                            $(".topInfo").nextAll().show();
                            $(".topInfo").prevAll().show();
                            $(".topInfo").hide();
                        }
                    });

                });
                
                //AJAX 获取详情信息
                function ajaxShowTop(){
                    
                    var url = $(".top_fixed_lift_title").attr("data-url");
                    var param = $(".top_fixed_lift_title").attr("data-param");
                    url = url+"?"+param;
                    $.get(url,{}, function(data){
                        data = $.parseJSON(data);
                        var html = "";
                        
                        $.each(data.row_list,function(i,v){
                            
                            var sec1_html = "";
                            var sec2_html = "";
                            var sec3_html = "";
                            
                            var title_html = "<div class=\\"title\\">"+v.title+"</div>";
                            
                            $.each(v.list,function(ii,vv){
                                sec1_html += "<td>"+vv.give_title+"</td>";
                                sec2_html += "<td>"+vv.number_sum+"</td>";
                                sec3_html += "<td>"+vv.status_str+"</td>";
                            });
                            sec1_html = "<tr>"+sec1_html+"</tr>";
                            sec2_html = "<tr>"+sec2_html+"</tr>";
                            sec3_html = "<tr>"+sec3_html+"</tr>";
                            var sec_html = "<table class=\\"table-sec\\"><tbody>"+sec1_html+sec2_html+sec3_html+"</tbody></table>";
                            
                            html += "<div class=\\"item\\">"+title_html+sec_html+"</div>";
                        });
                        
                        $(".topInfo").html(html);
                    });
                }
                
            </script>
        ';

        return $html;
    }

    //产品统计
    public static function giveHtml($url = '',$mill_list = []){

        $tab = '<div class="title flex flex-center flex_title" data-url="'.$url.'">
                    <span data-param="is_day=">峰值当量</span>
                    <span class="on" data-param="is_day=1">当日总产量</span>';
        if(!empty($mill_list)){
            foreach ($mill_list as $mk=>$ms){
                $tab .= '<span data-param="mill_id='.$mk.'">'.$ms.'</span>';
            }
        }
        $tab .= '</div>';

        $html = '
        <div class="top-g">
            '.$tab.'
            <div class="chartsBox s_center">
            </div>
        </div>
        <script type="text/javascript">
            $(function (){
                $(".top-g span").click(function () {
                    $(this).addClass("on").siblings().removeClass("on");
                    
                    //AJAX获取数据
                    $(".flex_title").attr("data-param",$(this).attr("data-param"));
                    //AJAX 加载数据
                    flexAjaxShow();
                    
                });
                
                $(".top-g span.on").click();
        
            });
            
            //AJAX 获取详情信息
            function flexAjaxShow(){
                
                var url = $(".flex_title").attr("data-url");
                var param = $(".flex_title").attr("data-param");
                url = url+"?"+param;
                $.get(url,{}, function(data){
                    data = $.parseJSON(data);
                    
                    var html = "";
                    var chart_width = (98/((data.row_list).length))+"%";
                    
                    $.each(data.row_list,function(i,v){
                        
                       html += "<div class=\\"charts\\" style=\\"flex: 0 0 "+chart_width+"\\">"+
                                "<div class=\\"h1 s_center\\">"+
                                    "<font>"+v.title+"</font>"+
                                    "<label>"+v.status_time+"</label>"+
                                "</div>"+
                                "<div class=\\"h2 s_center\\">"+
                                    "<font>"+v.number_sum+"件</font>"+
                                    "<label>"+v.area_sum+"㎡</label>"+
                                "</div>"+
                                "<div class=\\"chart c-charts\\" id=\\"c-charts"+i+"\\" ></div>"+
                            "</div>";
                        
                    });
                    
                    $(".chartsBox").html(html);
                    chartInit();
                });
            }
            
            //渲染图画
            function chartInit(){
                //渲染图画
                $.each($(".c-charts"),function(i,obj){
                    var id = $(obj).attr("id");
                    if(((i+1)%2) == 0)chart1(id);
                    else chart(id);
                });
            }
            
            //图画
            function chart(id){
                var chartDom = document.getElementById(id);
                var myChart = echarts.init(chartDom);
                var option;
        
                option = {
                    color: [\'#80FFA5\', \'#00DDFF\', \'#37A2FF\', \'#FF0087\', \'#FFBF00\'],
                    title: {
                        text: \'Gradient Stacked Area Chart\',
        
                        show: false
                    },
                    tooltip: {
                        trigger: \'axis\',
                        axisPointer: {
                            type: \'cross\',
                            label: {
                                backgroundColor: \'#6a7985\'
                            }
                        }
                    },
                    legend: {
                        show: false,
                        data: [\'Line 1\', \'Line 2\', \'Line 3\', \'Line 4\', \'Line 5\']
                    },
                    grid: {
                        left: \'10px\',
                        right: \'10px\',
                        bottom: \'0\',
                        top: \'0\',
                    },
                    xAxis: [
                        {
                            show: false,
                            type: \'category\',
                            boundaryGap: false,
                            data: [\'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\', \'Sun\']
                        }
                    ],
                    yAxis: [
                        {
                            type: \'value\',
                            show: false
                        }
                    ],
                    series: [
                        {
                            name: \'Line 1\',
                            type: \'line\',
                            stack: \'Total\',
                            smooth: true,
                            lineStyle: {
                                color: \'#A4E1DC\',    // 折线的颜色
                                width: 2,            // 折线的宽度
                                type: \'solid\',       // 折线的类型，支持 solid、dashed、dotted
                            },
                            showSymbol: false,
                            areaStyle: {
                                opacity: 0.8,
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                    {
                                        offset: 0,
                                        color: \'RGBA(187, 237, 241, 1)\'
                                    },
                                    {
                                        offset: 1,
                                        color: \'RGBA(255, 255, 255, 1)\'
                                    }
                                ])
                            },
                            emphasis: {
                                focus: \'series\'
                            },
                            data: [140, 232, 101, 264, 90, 340, 250]
                        }
                    ]
                };
        
                option && myChart.setOption(option);
            }
            //图画2
            function chart1(id){
                var chartDom1 = document.getElementById(id);
                var myChart1 = echarts.init(chartDom1);
                var option1;
        
                option1 = {
                    xAxis: {
                        type: \'category\',
                        data: [\'Mon\', \'Tue\', \'Wed\', \'Thu\', \'Fri\', \'Sat\', \'Sun\'],
                        show:false
                    },
                    grid: {
                        left: \'10px\',
                        right: \'10px\',
                        bottom: \'0\',
                        top: \'0\',
                    },
                    yAxis: {
                        type: \'value\',
                        show:false
                    },
                    series: [
                        {
                            data: [120, 200, 150, 80, 70, 110, 130],
                            type: \'bar\',
                            color: \'#B9CDF0\',
                        }
                    ]
                };
        
                option1 && myChart1.setOption(option1);
            }
        </script>
        ';

        return $html;
    }

    //发货单列表
    public static function ajaxLeftHtml($parent = [],$url = ''){

        $back_btn = '';
        if(!empty($parent['back_url']))$back_btn = '$(".back-btn").attr("onclick","location.href=\''.$parent['back_url'].'\';return false;");';

        $html = '
            <div class="pricing_menu_left_show fixed_lift_title" data-url="'.$url.'" data-param="" data-parent-url="'.$parent['url'].'" data-parent-param="'.$parent['param'].'"><img src="'.config('template.tpl_replace_string')['__HOME_IMG__'].'/leftright.png"></div>
            <div class="pricing_menu_left pm_hide">
                <div class="pricing_menu_show">
                    <form class="layui-form pricing_menu_title">
                        <div class="pricing_menu_title_one" style="text-align: left">'.$parent['title'].'</div>
                        <div class="layui-input-wrap">
                                <div class="layui-input-prefix">
                                    <i class="layui-icon layui-icon-search"></i>
                                </div>
                                <input type="text" name="keyword" value="" placeholder="搜索" class="layui-input" lay-affix="clear">
                            </div>
                        <button class="layui-btn layui-btn-xs" lay-submit lay-filter="table-search">搜索</button>
                        <div class="pm_hide pricing_menu_title_one">取消</div>
                        <img class="pm_hide pricing_menu_title_one_img" src="'.config('template.tpl_replace_string')['__HOME_IMG__'].'/leftright.png">
                    </form>
                    <table id="fixed_table" lay-filter="fixed_table"></table>
                </div>
    
            </div>
        
            <script type="text/javascript">
                $(function(){
                
                    //重置返回按钮的url
                    '.$back_btn.'
                    
                    $("body").click(function(e) {
                        var obj = $(e.target);
                        
                        //打开弹出框
                        var obj_parent = obj.parents(".pricing_menu_left_show");
                        if(obj.is(".pricing_menu_left_show") || obj_parent.is(".pricing_menu_left_show")) {
                            obj = obj.is(".pricing_menu_left_show")?obj:obj_parent;
                            
                            var url = $(obj).attr("data-url");
                            var param = $(".fixed_lift_title").attr("data-param");
                            if(param)param = (url.indexOf("?") < 0 ? "?" : "&")+param;
                            
                            //AJAX 加载数据
                            ajaxList(url+param);
                            
                            $(".pricing_menu_left").show(300);
                            $(".pricing_menu_show").css("margin-left","0");
                            $(".pricing_menu_left_show").hide();
                            
                        }
                        //关闭弹出框
                        else if(obj.is(".pm_hide")){
                            $(".pricing_menu_show").css("margin-left","-480px");
                            $(".pricing_menu_left").hide(300);
                            $(".pricing_menu_left_show").show();
                        }
                    });

                });
                
                //AJAX 获取列表信息
                function ajaxList(url){
                    
                    $.get(url,{}, function(data){
                        data = $.parseJSON(data);
                        //渲染表格
                        fixedTable(url,data);
                        
                    });
                    
                }
                function fixedTable(url,data){
                
                    //表头
                    var columns = [];
                    //数据
                    var row_list = data.row_list;
                    
                    $.each(data.columns,function(i,v){
                        //居中
                        v.align = "center";
                        //列表内容
                        v.templet = function(d){
                            return d[v.field] != null?d[v.field]:"";
                        };
                        columns[i] = v;
                    });
                    columns = [columns];
                    
                    //设置css样式
                    var css = ".layui-table-view .layui-table {width: 100%;}";
                    //设置分页样式
                    var page = {
                        theme: "#1E9FFF",
                        prev: "上一页",
                        next: "下一页",
                        layout:["prev", "page", "next"]
                    };
                    
                    layui.use(["table"], function(){
                        var table = layui.table;
                        var form = layui.form;
        
                        var table_options = {
                            elem: "#fixed_table",
                            cols: columns,
                            data: row_list,
                            page: page,
                            limit: 28, // 数据表格默认全部显示
                            skin: "line",
                            css: css,
                            height: "887",
                            done: function(res, curr, count) {
                                
                                // 设置css样式
                                $(".pricing_menu_left").find(".layui-laypage a").addClass("fixed-page");
                                $("td[data-field=right_str]").find("div").html("<i class=\\"layui-icon layui-icon-right\\" style=\\"font-size: 14px;font-weight: bolder;\\"></i>");
                                // 监听单元格点击事件
    
                            }
                        };
                        // 渲染表格
                        table.render(table_options);
                        
                        // 搜索按钮事件
                        form.on("submit(table-search)", function(data){
                            var field = data.field; // 获取搜索关键字
                            var param = "";
                            $.each(field,function(i,v){
                                param += i+"="+v;
                            });
                            if(param)param = (url.indexOf("?") < 0 ? "?" : "&")+param;
                            //AJAX 加载数据
                            ajaxList(url+param);
                            return false; // 阻止表单提交
                        });
                        
                        // 行单击事件( 双击事件为: rowDouble )
                        table.on("row(fixed_table)", function(obj){
                            var data = obj.data; // 获取当前行数据
                            
                            var parent_url = $(".pricing_menu_left_show").attr("data-parent-url");
                            var parent_param = $(".pricing_menu_left_show").attr("data-parent-param");
                            //点击跳转
                            location.href = parent_url+"?"+parent_param+"="+data[parent_param];
                            //// 显示 - 仅用于演示
                            //layer.msg(\'当前行数据：<br>\'+ JSON.stringify(data), {
                            //    offset: \'65px\'
                            //});
                            //// 标注当前点击行的选中状态
                            //obj.setRowChecked({
                            //    type: \'radio\' // radio 单选模式；checkbox 复选模式
                            //});
                        });
        
                    });
                
                }
                
            </script>
        ';

        return $html;
    }

    //各工艺统计
    public static function topStatSpeedHtml($url = ''){

        $html = '
        <div class="all">
            <div id="all" class="charts"></div>
        </div>
        <div class="chartBox flex flex-center wrap" style="margin-right: 120px">
        </div>
        
            <script type="text/javascript">
            
                $(function(){
                    
                    //AJAX 加载数据
                    ajaxList("'.$url.'");

                });
                
                //AJAX 获取列表信息
                function ajaxList(url){
                    
                    $.get(url,{}, function(data){
                        data = $.parseJSON(data);
                        //渲染图形统计
                        fixedChart(data);
                        
                    });
                    
                }
                //渲染图形统计
                function fixedChart(data){
                    data = data.data;
                    //总的统计
                    cheartAll(data.all);
                    //细分统计
                    cheartList(data.list);
                }
                //总的图形统计
                function cheartAll(data) {
                    var chartDom = document.getElementById("all");
                    var myChart = echarts.init(chartDom);
                    var option;
                    option = {
                        tooltip: {
                            trigger: "item"
                        },
            
                        title: {
                            text: data.title,
                            left: "center"
                        },
                        legend: {
                            orient: "vertical",
                            left: "right",
                            top:"bottom"
                        },
                        series: [
                            {
                                name: data.title,
                                type: "pie",
                                radius: "50%",
                                itemStyle: {
                                    borderRadius: 20,
                                    borderColor: "#fff",
                                    borderWidth: 2
                                },
                                data: [
                                    { value: data.number_sum, name: "数量(件)" ,
                                        itemStyle:{
                                            color:"#d97559"
                                        }},
                                    { value: data.row_area_sum, name: "面积(㎡)",
                                        itemStyle:{
                                            color:"#e4c477"
                                        } },
                                    { value: data.j_number_sum, name: "积存数量(件)" ,
                                        itemStyle:{
                                            color:"#daa67b"
                                        }},
                                    { value: data.j_row_area_sum, name: "积存面积(㎡)",
                                        itemStyle:{
                                            color:"#4e9c8f"
                                        } }
                                ],
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: "rgba(0, 0, 0, 0.5)"
                                    }
                                }
                            }
                        ]
                    };
                    option && myChart.setOption(option);
                }
                //细分图形统计
                function cheartList(data) {
                    $.each(data,function(i,data){
                        var html = \'<div id="chart\'+i+\'" class="charts-li charts1 "></div>\';
                        $(".chartBox").append(html);
                        
                        var chartDom = document.getElementById("chart"+i);
                        var myChart = echarts.init(chartDom);
                        var option = {
                            tooltip: {
                                trigger: "item"
                            },
                
                            legend: {
                                orient: "vertical",
                                left: "right",
                                top:"bottom"
                            },
                            graphic:{
                                type: "text",
                                left: "34.5%",
                                top: "middle",
                                style: {
                                    text: data.title,
                                    textAlign: "center",
                                    fill: "#333",
                                    fontSize: 13,
                                    fontWeight: "bold"
                                }
                            },
                            series: [
                                {
                                    name: data.title,
                                    type: "pie",
                                    center:["38%","50%"],
                                    radius: ["50%", "80%"],
                                    itemStyle: {
                                        borderRadius: 10,
                                        borderColor: "#fff",
                                        borderWidth: 2
                                    },
                                    data: [
                                        { value: data.number_sum, name: "数量(件)",
                                            itemStyle:{
                                                color:"#2478F2"
                                            }},
                                        { value: data.row_area_sum, name: "面积(㎡)",
                                            itemStyle:{
                                                color:"#84B7F9"
                                            } },
                                        { value: data.j_number_sum, name: "积存数量(件)",
                                            itemStyle:{
                                                color:"#5F9CF8"
                                            }},
                                        { value: data.j_row_area_sum, name: "积存面积(㎡)",
                                            itemStyle:{
                                                color:"#CEE5FC"
                                            } }
                                    ],
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: "rgba(0, 0, 0, 0.5)"
                                        }
                                    }
                                }
                            ]
                        };
                        option && myChart.setOption(option);
                    });
                }
            
                
            </script>
        ';

        return $html;
    }

    // 工程阶段统计
    public static function statOrderStatus($starttime = 0,$endtime = 0,$time_input = '')
    {
        //默认今天
        if(empty($starttime))$starttime = strtotime(date("Y-m-d", (time())));
        if(empty($endtime))$endtime = strtotime(date("Y-m-d 23:59:59", time()));

        if(!empty($time_input)){
            $time_input = explode(' - ',$time_input);
            $starttime = strtotime($time_input[0]);
            $endtime = strtotime(date("Y-m-d 23:59:59", strtotime($time_input[1])));
        }

        $date = date('Y-m-d', $starttime);
        $end_date = date('Y-m-d 23:59:59', $endtime);
        //设计
        $bill_where[] = ['o.archives_bill_time','between time',[$date,$end_date]];
        $bill = Db::name('mill_order')
            ->alias('o')
            ->field('sum((a.one_area*a.number)) as area_sum,sum(a.number) as number_sum')
            ->leftJoin('mill_order_archives a','o.id=a.order_id')
            ->where($bill_where)
            ->find();

        //开料
        $status1_where[] = ['g.status','=',1];
        $status1_where[] = ['g.status1_time','between time',[$date,$end_date]];
        $status1 = Db::name('mill_order_archives_give')
            ->alias('g')
            ->field('sum(a.one_area) as area_sum,count(g.id) as number_sum')
            ->leftJoin('mill_order_archives a','a.id=g.archives_id')
            ->where($status1_where)
            ->find();

        //打磨
        $status2_where[] = ['g.status','=',2];
        $status2_where[] = ['g.status2_time','between time',[$date,$end_date]];
        $status2 = Db::name('mill_order_archives_give')
            ->alias('g')
            ->field('sum(a.one_area) as area_sum,count(g.id) as number_sum')
            ->leftJoin('mill_order_archives a','a.id=g.archives_id')
            ->where($status2_where)
            ->find();

        //焊接
        $status3_where[] = ['g.status','=',3];
        $status3_where[] = ['g.status3_time','between time',[$date,$end_date]];
        $status3 = Db::name('mill_order_archives_give')
            ->alias('g')
            ->field('sum(a.one_area) as area_sum,count(g.id) as number_sum')
            ->leftJoin('mill_order_archives a','a.id=g.archives_id')
            ->where($status3_where)
            ->find();

        //发货
        $status4_where[] = ['g.status','=',4];
        $status4_where[] = ['g.status4_time','between time',[$date,$end_date]];
        $status4 = Db::name('mill_order_archives_give')
            ->alias('g')
            ->field('sum(a.one_area) as area_sum,count(g.id) as number_sum')
            ->leftJoin('mill_order_archives a','a.id=g.archives_id')
            ->where($status4_where)
            ->find();

        $bill['number_sum'] = floatval($bill['number_sum']);
        $status1['number_sum'] = floatval($status1['number_sum']);
        $status2['number_sum'] = floatval($status2['number_sum']);
        $status3['number_sum'] = floatval($status3['number_sum']);
        $status4['number_sum'] = floatval($status4['number_sum']);

        $bill['area_sum'] = floatval($bill['area_sum']);
        $status1['area_sum'] = floatval($status1['area_sum']);
        $status2['area_sum'] = floatval($status2['area_sum']);
        $status3['area_sum'] = floatval($status3['area_sum']);
        $status4['area_sum'] = floatval($status4['area_sum']);

        $re = [
            'bill'          =>  $bill,
            'status1'       =>  $status1,
            'status2'       =>  $status2,
            'status3'       =>  $status3,
            'status4'       =>  $status4
        ];

        return $re;
    }

    //-------------------------------------------- 仓库板块统计 ------------------------------------------------------
    //采购单统计
    public static function materialHtml($url = '',$option = '',$model = ['rank','charts','year']){

        $width = '100%';

        //if($i == 2)$width = 'calc(100% - 320px)';
        //elseif ($i == 3)$width = 'calc(100% - 519px)';

        $html = '<div class="charts" id="echarts" style="width:'.$width.'"></div>';

        $js = '<script type="text/javascript">
                
                $(function(){
                    echartsInit();
                });
                //初始化echarts
                function echartsInit (id,data) {
        
                    var chartDom = document.getElementById("echarts");
                    var myChart = echarts.init(chartDom);
                    
                    var option = '.$option.';
        
                    option && myChart.setOption(option);
                }
                
                
            </script>';

        return $html.$js;

    }
    //------------------------------------------ 仓库板块统计 END ----------------------------------------------------

}
